package com.fgsort;

import java.awt.Color;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import java.awt.BorderLayout;
import java.awt.SystemColor;
import java.awt.Font;

public class OutputPanel extends JPanel {
	private static final long serialVersionUID = 1L;
	private String newline = "\n";
	
	private JTextPane textpaneOutput;
	//final Document doc; 
	
	public OutputPanel(String panelTitle)	{

		setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.gray), panelTitle));
		
		// create text output poanel on rhs
		textpaneOutput = new JTextPane();
		add(textpaneOutput);
	
		textpaneOutput.setFont(new Font("Tahoma", Font.PLAIN, 11));
		textpaneOutput.setForeground(new Color(0, 128, 0));
		textpaneOutput.setBackground(SystemColor.control);
		textpaneOutput.setEditable(false);
	    JScrollPane scrollPane = new JScrollPane(textpaneOutput);
	    setLayout(new BorderLayout());
	    add(scrollPane);
	}

	public void setDisplayOutput(String displayString)	{
	
        try {
        	Document doc = textpaneOutput.getDocument();
			doc.insertString(doc.getLength(), displayString+newline, null);
		} catch (BadLocationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
}
